<?php

// Si le fichier de qui d�finie les constantes n'a pas encore �t� appel� on le charge
if (!defined('CONFIGURATION_FILE_LOADED'))
    include( $_SERVER['DOCUMENT_ROOT'] . '/' . URL_SITE . '/includes/configuration_include.php');

include( PATH_MODELS . 'create_playlist_model.php');
include( PATH_VIEWS . 'create_playlist_view.php');
include( PATH_MODELS . 'db_connexion_model.php');

$bdd = model_db_connexion();

// Si l'utilisateur est deja logue
if (!isset($_SESSION['id_user'])) {
    $str = view_not_connected();
} else {
    if (!empty($_POST['nom']) && !empty($_POST['autheur'])) {
        
        $nom = $_POST["nom"];
        $autheur = $_POST["autheur"];
        $ambiance = $_POST["ambiance"];
        $genre1 = $_POST["genre1"];
        $genre2 = $_POST["genre2"];
        $genre3 = $_POST["genre3"];
        $heure = $_POST["heure"];
        $soundcloud = $_POST["soundcloud"];
        
        // ajoute une playlist 
        model_create_playlist($bdd, $nom, $autheur, $ambiance, $genre1, $genre2, $genre3, $heure, $soundcloud);

        echo '<span id="annonce">Votre playlist est créer !</span>';
        $str = create_playlist();
    } else if (empty($_POST['nom']) && empty($_POST['autheur'])){
        
        
        $str = create_playlist();
    }
    else {
        echo'<span id="annonce">Veuillez remplir tout les champs du formulaire</span>';
        $str = create_playlist();
    }
}
?>


<?php

echo $str . "\n";
?>